package itheima.d01;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class ChatRunnable  implements Runnable{
    private Socket socket;

    public ChatRunnable(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try (
                InputStream is = socket.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(is));
                )
        {
            while ( true){
                String msg = br.readLine();
                System.out.println("接收到客户端的消息：" + msg);
                if ("886".equals(msg)){
                    System.out.println("客户端退出了聊天室");
                }
            }
        } catch (Exception e) {
            System.out.println(socket.getRemoteSocketAddress()+"客户端强制退出");;
        }

    }
}
